package com.xiaoc.bulldozer.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogUtils {

    private static final Logger logger = LoggerFactory.getLogger(LogUtils.class);

    private static final String BALANCE_LOG_FORMATER = "userId=%s,balance=%s,amount=%s,newBalance=%s,balanceType=%s,balanceDetailType=%s,time=%s";

    /**
     * 日志记录余额变更数据
     * 
     * @param userId 用户ID
     * @param balance 原余额
     * @param amount 变更金额
     * @param type 类型
     */
    public static void logBalance(Integer userId, Integer balance, Integer amount, Integer newBalance, Integer balanceType, Integer balanceDetailType) {
        try {
            logger.info(String.format(BALANCE_LOG_FORMATER, userId, balance, amount, newBalance, balanceType, balanceDetailType, System.currentTimeMillis()));
        } catch (Exception e) {
            logger.error("logUtils error userId:" + userId + ",balance:" + balance + ",amount:" + amount + ",balanceType:" + balanceType + ",balanceDetailType:" + balanceDetailType , e);
        }
    }
}
